import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

public class Scheme {
  private SchemeType schemeType;

  public Scheme(SchemeType schemeType) {
    this.schemeType = schemeType;
  }

  public void crop(List<List> exList) {
      for (int i = 3; i < exList.size(); i += 3) {
        exList.remove(i);
        if(i == exList.size())break;
        exList.remove(i);
      }
  }

  public List<List> addRestDays(List<List> exList,int days) {
	List<Excercise> breakList = new ArrayList<Excercise>();
	Excercise restDay = new Excercise("RestDay",ExceriseType.valueOf("BREAKDAY"));
	breakList.add(restDay);
    if (schemeType == SchemeType.THREEONE) {
      for (int i = 3; i < exList.size(); i += 4) {
        exList.add(i, breakList);
        
      }
    } else if (schemeType == SchemeType.FIVETWO) {
      for (int i = 5; i < exList.size(); i += 7) {
        exList.add(i, breakList);
        exList.add(i, breakList);
        exList.remove(exList.size()-1);
        exList.remove(exList.size()-1);
      }
    }
    while(exList.size()>days){
    	exList.remove(exList.size()-1);
    }
    return exList;
  }

  public List<List> addRestDays(List<List> exList, int startingDay,int days, Integer... breakDays) {
	List<Excercise> breakList = new ArrayList<Excercise>();
	Excercise restDay = new Excercise( "RestDay", ExceriseType.valueOf( "BREAKDAY" ));
	breakList.add(restDay);
    List<Excercise> restList = new ArrayList<Excercise>();
    restList.add( restDay );
    for (int i = 0; i < breakDays.length; i++) {
      breakDays[i] -= startingDay;
      if (breakDays[i] < 0) {
        breakDays[i] += 7;
      }
    }
    for (int i = 0; i < exList.size(); i++) {
      for (int y = 0; y < breakDays.length; y++) {
        if (i == breakDays[y]) {
          exList.add(i, restList);
         
          breakDays[y] += 7;
        }
      }
    }
    while(exList.size()>days){
    	exList.remove(exList.size()-1);
    }
    return exList;
  }

  public SchemeType getType() {
    return schemeType;
  } 
  
 	public int findStartDay(String startingDay) {
 		DateFormatSymbols dateFormat = new DateFormatSymbols();
		String[] namesOfWeekDay = dateFormat.getWeekdays();
		List<String> daysNames=Arrays.asList(namesOfWeekDay);
		int ind =-1;
		for( ind=1;ind<daysNames.size();ind++){
			if(daysNames.get(ind).equalsIgnoreCase(startingDay)){
				if(ind>0)ind = ind-1;
				else ind = 0;
				break;
			}
		}
		return ind;
	}

	public Integer[] findRestDays(String[] namesOfRestDay){
		Integer find=-1;
		DateFormatSymbols dateFormat = new DateFormatSymbols();
		String[] namesOfWeekDay = dateFormat.getWeekdays();
		Integer[] finishfindDays;
		List<Integer> findDays=new ArrayList<Integer>();
		List<String> daysNames=Arrays.asList(namesOfWeekDay);
		for(int i=0;i<namesOfRestDay.length;i++){
			for(int ind=1;ind<daysNames.size();ind++){
				if(daysNames.get(ind).equalsIgnoreCase(namesOfRestDay[i])){
					if(ind>0)find = ind-1;
					else find = 0;
					break;
				}
			}
		findDays.add(find);
		find = new Integer(0);
		}
		Object[] finishDays = findDays.toArray();
		finishfindDays = new Integer[finishDays.length];
		for (int ind = 0;ind<finishDays.length;ind++){
			finishfindDays[ind]= (Integer)finishDays[ind];
		}
		return finishfindDays;
	}
}

